#ifndef __SIPSRV_TRANSACTION_HPP__
#define __SIPSRV_TRANSACTION_HPP__

#include "SipResipConfigure.hpp"
#include "resip/stack/SipMessage.hxx"
#include "resip/stack/ApplicationMessage.hxx"

using namespace resip;

namespace wtsip{

class CSipSrvTransaction;
class CSipUserAgent;
class CSipDialogBase;

class RESIP_PUBLIC CSipSrvTransactionListener{
public:
    virtual bool onRequest(CSipSrvTransaction& srvtran, SipMessage& msg) = 0;

    virtual bool onDestroy(CSipSrvTransaction& srvtran) = 0;

    //virtual bool onResponse(CSipSrvTransaction& srvtran, SipMessage& msg) = 0;
};


class RESIP_PUBLIC CSipSrvTransaction{
private:
    typedef enum
    {
        SrvInitial = 0,
        SrvProvisional,
        SrvCompleted,
        SrvFailed
    } SrvTranState;
public:
    CSipSrvTransaction(SipMessage& request, CSipUserAgent& ua);

    virtual ~CSipSrvTransaction();

    virtual bool processIncoming(SipMessage* msg);

    virtual bool processTimeOut(ApplicationMessage* msg);

    virtual bool send(std::auto_ptr<SipMessage> msg);

    bool registerListener(CSipSrvTransactionListener* callback);

    bool unregisterListener();

    virtual SipMessage* createResponse(int code);
    
    bool bindDialog(CSipDialogBase* dialog);

    SipMessage& getRequest();

    resip::Data& getTid();

    CSipDialogBase* getBindDlg();

    bool hasListener(){ return (m_listener != NULL); }

protected:
    virtual bool setState(int state);

protected:
    int m_State;

    SipMessage m_request;

    CSipUserAgent& m_ua;

    resip::Data m_tid;

    MethodTypes m_mth;

    CSipDialogBase* m_bindDialog;

    CSipSrvTransactionListener* m_listener;
};



}//namespace

#endif

